package com.esisa.swing;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LabeledTextField extends JPanel {
	public LabeledTextField(String label, int size) {
		this(label, size, 0);
	}
	
	public LabeledTextField(String label, int size, int labelWidth) {
		setLayout(new FlowLayout(FlowLayout.LEFT));
		JLabel l1 = new JLabel(label + " :");
		if (labelWidth>0) l1.setPreferredSize(new Dimension(labelWidth, 20));
		JTextField t1 = new JTextField(size);
		add(l1);
		add(t1);
	}
	public String getText(){
		JTextField j = (JTextField)getComponent(1);
		return j.getText();
	}
	public JTextField getTextField(){
		JTextField j = (JTextField)getComponent(1);
		return j;
	}
	
	public String getLabelText(){
		JLabel l = (JLabel)getComponent(0);
		return l.getText();
	}
	public JLabel getLabel(){
		JLabel l = (JLabel)getComponent(0);
		return l;
	}
	public void setText(String text){
		JTextField j = (JTextField)getComponent(1);
		j.setText(text);
	}
	public void AddKeyListner(KeyListener listner){
		JTextField j = (JTextField)getComponent(1);
		j.addKeyListener(listner);		
	}
	public void AddMouseListner(MouseListener listner){
		JTextField j = (JTextField)getComponent(1);
		j.addMouseListener(listner);		
	}
	
}
